package com.manor.main.dialog

import android.content.Context
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.bitmap.CenterCrop
import com.bumptech.glide.request.RequestOptions
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.lxj.xpopup.XPopup
import com.lxj.xpopup.impl.FullScreenPopupView
import com.manor.common.bean.UserNBean
import com.manor.main.R
import kotlinx.android.synthetic.main.popup_mine_medal.view.*

/**
 *


 * @date  2020/6/2  11:05
 * @version 1.0
 */
class MineMedalPopup(context: Context,val dataList :MutableList<UserNBean.MedalBean>) : FullScreenPopupView(context) {
    private var mAdapter: MAdapter? = null

    override fun getImplLayoutId(): Int = R.layout.popup_mine_medal


    override fun onCreate() {
        super.onCreate()
        titleView.text = "淘米奖章"
        btn_back.setOnClickListener { dismiss() }

        initRecycler()
    }
    

    private fun initRecycler() {
        mAdapter = MAdapter(R.layout.item_mine_medal, dataList)
        mRecycler.layoutManager = androidx.recyclerview.widget.GridLayoutManager(context, 3, androidx.recyclerview.widget.GridLayoutManager.VERTICAL, false)
        mRecycler.setHasFixedSize(true)
        mRecycler.adapter = mAdapter
        mAdapter?.run {
            this.setOnItemClickListener { _, _, position ->
                XPopup.Builder(context)
                        .asCustom(MedalShowPopup(context,dataList[position]))
                        .show()
            }
        }
    }



    private class MAdapter(layout: Int, data: MutableList<UserNBean.MedalBean>) : BaseQuickAdapter<UserNBean.MedalBean,
            BaseViewHolder>(layout, data) {
        override fun convert(helper: BaseViewHolder, item: UserNBean.MedalBean) {
            item.run {
                helper.setText(R.id.tv_text, name )
                Glide.with(context)
                        .load(if (status==1) icon else icon_out)
                        .error(R.mipmap.defaulthead)
                        .apply(RequestOptions().transform( CenterCrop()))
                        .into(helper.getView(R.id.iv_img))
            }
        }

    }


}